﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Email Template Repository
    /// </summary>
    public class FeedbackRepository : IFeedbackRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Feedback Details by Template Name
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<Feedback> FindFeedbackByName(string strQuery)
        {
            return _db.Feedbacks.Where(d => d.Name.Contains(strQuery));
        }

        /// <summary>
        /// Get All Templates
        /// </summary>
        /// <returns></returns>
        public IQueryable<Feedback> FindAllFeedback()
        {
            return _db.Feedbacks;
        }

        /// <summary>
        /// Get Feedback by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Feedback GetFeedbackById(int id)
        {
            return _db.Feedbacks.SingleOrDefault(d => d.FeedbackId == id);
        }

        /// <summary>
        /// Add Feedback in the Database
        /// </summary>
        /// <param name="feedback"></param>
        public void Add(Feedback feedback)
        {
            _db.Feedbacks.AddObject(feedback);
        }

        /// <summary>
        /// Delete Template from Database
        /// </summary>
        /// <param name="feedback"></param>
        public void Delete(Feedback feedback)
        {
            _db.Feedbacks.DeleteObject(feedback);
        }

        /// <summary>
        /// Save template in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}